Skip to content

eunit: Pass node name to {node, ...} instantiator - #10788

Merged
Mikaka27 merged 2 commits into
erlang:maintfrom
williamthome:eunit/fix-node-instantiator
Mar 24, 2026
Merged

eunit: Pass node name to {node, ...} instantiator#10788
Mikaka27 merged 2 commits into
erlang:maintfrom
williamthome:eunit/fix-node-instantiator

Conversation

@williamthome

@williamthome williamthome commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

The migration from slave to peer in OTP-28 discarded the node name returned by peer:start_link/1, passing the Pid to the instantiator instead of the node name. This made {node, ...} unusable since the instantiator needs the node name to use with {spawn, Node, Tests} or erpc:call/4.

Capture the node name and wrap the instantiator so it receives the node name as an atom. Restore auto-start of net_kernel for non-distributed nodes so {node, ...} works out of the box.

https://erlangforums.com/t/eunit-node-instantiator-broken-in-otp-28-x/5465?u=williamthome

@github-actions

github-actions Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

  2 files   12 suites   3m 17s ⏱️
110 tests 106 ✅ 4 💤 0 ❌
126 runs  122 ✅ 4 💤 0 ❌

Results for commit a1208ab.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@williamthome
williamthome force-pushed the eunit/fix-node-instantiator branch from 4932e8a to cf74268 Compare March 1, 2026 16:36
@IngelaAndin IngelaAndin added the team:PS Assigned to OTP team PS label Mar 2, 2026
@rlipscombe

Copy link
Copy Markdown
Contributor

Looks good to me. I checked it with the following:

-module(node_test).
-include_lib("eunit/include/eunit.hrl").

node_spawn_test_() ->
    {node, 'foo', fun(Node) ->
        {spawn, Node, [
            {setup, fun remote_setup/0, [
                fun remote/0
            ]}
        ]}
    end}.

remote_setup() ->
    % uncomment to assert that the setup is running on the new node.
    % ?assertEqual(moo, node()),
    ok.

remote() ->
    ?assertEqual(moo, node()),
    ok.

@Mikaka27

Mikaka27 commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Is automatic enabling of net_kernel safe now? It was disabled on 27 as well.

@williamthome

Copy link
Copy Markdown
Contributor Author

Is automatic enabling of net_kernel safe now? It was disabled on 27 as well.

Hmm I'm unsure. Where/when was it disabled in OTP 27? I've been trying to locate the specific change but haven't found it. Or do you mean the comments that already exist removed by this PR?

Note the auto-start is intentionally limited to EUnit's {node, ...} test context only and when node() is nonode@nohost, not a global re-enable. If there are specific safety concerns I should address, happy to add docs or a config flag.

Do you recommend removing the auto-start?

Comment thread lib/eunit/src/eunit_data.erl Outdated
'nonode@nohost' ->
M = list_to_atom(atom_to_list(Name)
++ "_eunit_master"),
case net_kernel:start([M, shortnames]) of

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that net_kernel:start/1 is deprecated -- per https://www.erlang.org/doc/apps/kernel/net_kernel.html#start/1 -- should this use net_kernel:start/2 instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks like you're right

@Mikaka27

Mikaka27 commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Is automatic enabling of net_kernel safe now? It was disabled on 27 as well.

Hmm I'm unsure. Where/when was it disabled in OTP 27? I've been trying to locate the specific change but haven't found it. Or do you mean the comments that already exist removed by this PR?

Note the auto-start is intentionally limited to EUnit's {node, ...} test context only and when node() is nonode@nohost, not a global re-enable. If there are specific safety concerns I should address, happy to add docs or a config flag.

Do you recommend removing the auto-start?

I meant the comment you removed, which is present on maint-27 branch as well. I don't know yet, will have to dig into the code and test if it's ok to do that.
Did you try running it with your change during system initialization? I think the comment is talking about various ways to execute code early as described here: https://www.erlang.org/doc/apps/erts/init.html

@williamthome
williamthome force-pushed the eunit/fix-node-instantiator branch 2 times, most recently from c00fbcc to 423ef55 Compare March 9, 2026 21:22
@williamthome

Copy link
Copy Markdown
Contributor Author

Did you try running it with your change during system initialization? I think the comment is talking about various ways to execute code early as described here: https://www.erlang.org/doc/apps/erts/init.html

Yes, I tested it during system initialization using all init flags (-eval, -s, -run, -S) on a non-distributed node. All passed. I've added these as test cases in eunit_SUITE:node_test/1 to ensure this keeps working.

@Mikaka27

Copy link
Copy Markdown
Contributor

Since this can be considered a bug, could you rebase your branch from patch-base-28 tag, so we can apply it to older branches? We will run this in our CI and see if there are any problems with this automatic start of net_kernel.

@williamthome

Copy link
Copy Markdown
Contributor Author

could you rebase your branch from patch-base-28 tag

Yep, can do, but I didn't find this tag:

image

Or do you mean patch-base-27 tag or maint-28 branch?

@Mikaka27

Copy link
Copy Markdown
Contributor

You're right, it doesn't exist, my bad. You can rebase from tag OTP 28.4

The migration from slave to peer in OTP-28 discarded the node
name returned by peer:start_link/1, passing the Pid to the
instantiator instead of the node name. This made {node, ...}
unusable since the instantiator needs the node name to use
with {spawn, Node, Tests} or erpc:call/4.

Capture the node name and wrap the instantiator so it receives
the node name as an atom. Restore auto-start of net_kernel
for non-distributed nodes so {node, ...} works out of the box.
@williamthome
williamthome force-pushed the eunit/fix-node-instantiator branch from 423ef55 to e02aa5c Compare March 11, 2026 19:07
@williamthome
williamthome changed the base branch from master to maint-28 March 11, 2026 19:09
@williamthome

Copy link
Copy Markdown
Contributor Author

You're right, it doesn't exist, my bad. You can rebase from tag OTP 28.4

Done.

@Mikaka27 Mikaka27 added testing currently being tested, tag is used by OTP internal CI and removed testing currently being tested, tag is used by OTP internal CI labels Mar 13, 2026
@Mikaka27
Mikaka27 changed the base branch from maint-28 to maint March 13, 2026 06:54
@Mikaka27 Mikaka27 added the testing currently being tested, tag is used by OTP internal CI label Mar 13, 2026

@rlipscombe rlipscombe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but I don't have write access to have the final say...

@Mikaka27
Mikaka27 merged commit 52a1131 into erlang:maint Mar 24, 2026
25 checks passed
@williamthome
williamthome deleted the eunit/fix-node-instantiator branch March 24, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants